package com.joker.controller;

import com.joker.pojo.Tag;
import com.joker.service.BlogService;
import com.joker.service.TagService;
import com.joker.vo.BlogQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Author JokerKS
 * @Date 2021/12/10 08:46
 * @Version 1.0
 */
@Controller
public class TagShowController {
	@Autowired
	private TagService tagService;

	@Autowired
	private BlogService blogService;

	@GetMapping("/tags/{id}")
	public String Tags(@PageableDefault(size = 5, sort = {"updateTime"}, direction = Sort.Direction.DESC) Pageable pageable,
					   @PathVariable Long id, Model model) {
		List<Tag> Tags = tagService.listTagTop(10000);
		if (id == -1) {
			id = Tags.get(0).getId();
		}
		//分类
		model.addAttribute("tags", Tags);
		//分页
		model.addAttribute("page", blogService.listBlog(id, pageable));
		//活跃显示
		model.addAttribute("activeTagId", id);
		return "tags";
	}
}
